Ext.onReady(function () {  
	Ext.QuickTips.init();
	var _panel=new Ext.Panel({
		title: '登陆',
		border: false,
		frame: false,
	    width: 300,
	    height: 190,
	    region: 'center',
	    layout: {
	    	type: 'vbox',
	        align: 'stretch'
	    },
        tools:[{
            type:'gear',
            tooltip: '配置',
            tooltipType:"qtip",
            handler: function(event, toolEl, panelHeader) {
            	console.log(1);
            }
        },
        {
            type:'help',
            tooltip: 'Get Help',
            callback: function(panel, tool, event) {
            	console.log(2);
            }
        }],
	    html: '<div id="login_form"></div>',
	    buttonAlign: 'center',
        buttons: [{
        	text:'登陆',
        	handler: login
        },
        {
        	text:'重置',
           	handler: reset
        }],
	    renderTo: 'login_box'
	});
	var v_code_img = Ext.create(Ext.Img, {
        style: "cursor:pointer ",
        src: U('Admin/Login/vCode'),
        title: '点击刷新',
        listeners: {
            click: function(){
            	v_code_img.setSrc(U('Admin/Login/vCode'));
            },
            element: "el"
        }
    });
	var login_form = Ext.create('Ext.form.Panel', {
	    border: false,
	    layout: 'anchor',
	    padding: 10,
	    defaults: {
//	        anchor: '100% 100%',
	    },
	    defaultType: 'textfield',
	    items: [{
	        fieldLabel: '用户名',
	        name: 'user',
	        minLength: 4,
	        maxLength: 20,
	        allowBlank: false,
	        blankText: '请输入用户名'
	    },{
	        fieldLabel: '密码',
	        name: 'pwd',
	        minLength: 6,
	        maxLength: 20,
	        inputType: 'password',
	        allowBlank: false,
	        blankText: '请输入密码'
	    },{
	        fieldLabel: '验证码',
	        name: 'vcode',
	        id: 'vcode',
	        minLength: 4,
	        maxLength: 4,
	        width: 210,
	        allowBlank: false,
	        blankText: '请输入验证码'
	    },{
	    	xtype: "container", 
	    	height: 25,
	    	width: 60,
	    	style: {
	    		position: 'absolute',
	    		bottom: '5px',
	    		right: '5px'
	    	},
            items: [v_code_img]
	    }],
	    renderTo: 'login_form'
	});
	function login(){
		login_form.getForm().submit({
            url: U('Admin/Login/loginAction'),  
        	clientValidation: true,
            success:function(form,action){
//            	Ext.toast({
//            	     html: '登陆成功,转链中...',
//            	     closable: false,
//            	     align: 't',
//            	     hide: function(){
//            	     }
//            	 });
             	window.location.href = U('Admin/Index/index');
            },  
            failure:function(form,action){
            	if(!login_form.getForm().isValid()){
            		return false;
            	}
            	if(action.result.success == false){
            		v_code_img.setSrc(U('Admin/Login/vCode'));
            		Ext.Msg.alert('警告', action.result.msg);
            	}
            }
		});
	}
	function reset(){
		v_code_img.setSrc(U('Admin/Login/vCode'));
		login_form.getForm().reset();
	}
}); 